package com.chenju.javastatic.adapter;

import com.chenju.javastatic.utils.EasyListUtils;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.tree.AnnotationNode;

import java.util.List;

public class FieldVisitorAdapter extends FieldVisitor {
    public int access;
    public String name;
    public String desc;
    public String signature;
    public Object value;
    public List<AnnotationNode> visibleAnnotations;
    public List<AnnotationNode> invisibleAnnotations;

    public FieldVisitorAdapter(int access, String name, String descriptor, String signature, Object value) {
        this(589824, access, name, descriptor, signature, value);
        if (this.getClass() != FieldVisitorAdapter.class) {
            throw new IllegalStateException();
        }
    }

    public FieldVisitorAdapter(int api, int access, String name, String descriptor, String signature, Object value) {
        super(api);
        this.access = access;
        this.name = name;
        this.desc = descriptor;
        this.signature = signature;
        this.value = value;
    }

    @Override
    public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
        AnnotationNode annotation = new AnnotationNode(descriptor);
        if (visible) {
            this.visibleAnnotations = EasyListUtils.add(this.visibleAnnotations, annotation);
        } else {
            this.invisibleAnnotations = EasyListUtils.add(this.invisibleAnnotations, annotation);
        }

        return annotation;
    }

    @Override
    public void visitEnd() {
    }
}
